home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / dev / gui / gtlayout.lha / Source / LT_GetAttributes.c < prev    next >
C/C++ Source or Header  |  1999-01-03  |  10KB  |  510 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1999 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /*****************************************************************************/
  15.  
  16. #include <stdarg.h>
  17.  
  18. /*****************************************************************************/
  19.  
  20. #include "Assert.h"
  21.  
  22. /*****************************************************************************/
  23.  
  24. LONG
  25. LT_GetAttributes(LayoutHandle *Handle,LONG ID,...)
  26. {
  27.     va_list VarArgs;
  28.     LONG    Result;
  29.  
  30.     va_start(VarArgs,ID);
  31.     Result = LT_GetAttributesA(Handle,ID,(struct TagItem *)VarArgs);
  32.     va_end(VarArgs);
  33.  
  34.     return(Result);
  35. }
  36.  
  37.  
  38. /*****************************************************************************/
  39.  
  40.  
  41. /****** gtlayout.library/LT_GetAttributesA ******************************************
  42. *
  43. *   NAME
  44. *    LT_GetAttributesA -- Inquire information on a gadget.
  45. *
  46. *   SYNOPSIS
  47. *    Value = LT_GetAttributesA(Handle,ID,Tags);
  48. *      D0                        A0   D0  A1
  49. *
  50. *    LONG LT_GetAttributesA(LayoutHandle *,LONG ID,struct TagItem *);
  51. *
  52. *    Value = LT_GetAttributes(Handle,ID,...);
  53. *
  54. *    LONG LT_GetAttributes(LayoutHandle *,LONG ID,...);
  55. *
  56. *   FUNCTION
  57. *    All objects created by the user interface layout code posess
  58. *    certain unique properties. The LT_GetAttributes() function will
  59. *    will inquire this information and return it. The implementation
  60. *    differs from gadtools.library/GT_GetGadgetAttrs in that you
  61. *    can inquire only a small subset of the object properties possible
  62. *    via the taglist passed in.
  63. *
  64. *   INPUTS
  65. *    Handle - Pointer to LayoutHandle structure.
  66. *
  67. *    ID - ID number of the object to inquire information about. This
  68. *        is the same value you passed via LA_ID to LT_New() when
  69. *        you created this object.
  70. *
  71. *    Tags - TagItem list to receive information about the object
  72. *        in question.
  73. *
  74. *
  75. *    LA_Left (LONG *) - Left edge of object.
  76. *
  77. *    LA_Top (LONG *) - Top edge of object.
  78. *
  79. *    LA_Width (LONG *) - Width of object.
  80. *
  81. *    LA_Height (LONG *) - Height of object.
  82. *
  83. *    LA_Chars (LONG *) - Width of object measured in character
  84. *        widths. (V9)
  85. *
  86. *    LA_Lines (LONG *) - Height of object measured in character
  87. *        heights. (V9)
  88. *
  89. *    LA_LabelLeft (LONG *) - Left edge of label text. (V9)
  90. *
  91. *    LA_LabelTop (LONG *) - Top edge of label text. (V9)
  92. *
  93. *    LABO_Object (Object *) - Returns a pointer to the BOOPSI object
  94. *        the BOOPSI_KIND object is based upon. (V10)
  95. *
  96. *            NOTE: Don't unlink the object or dispose of it or
  97. *                terrible things are bound to happen.
  98. *
  99. *    LAST_CursorPosition (LONG *) - Current position of the cursor
  100. *        in STRING_KIND and FRACTION_KIND objects. (V
  101. *
  102. *   RESULT
  103. *    The result depends on the object type:
  104. *
  105. *        VERTICAL_KIND:
  106. *        HORIZONTAL_KIND:
  107. *
  108. *            active page
  109. *
  110. *        SCROLLER_KIND:
  111. *
  112. *            current GTSC_Top value
  113. *
  114. *        TAPEDECK_KIND:
  115. *
  116. *            current LATD_Pressed value
  117. *
  118. *        LEVEL_KIND:
  119. *
  120. *            current LAVL_Level state
  121. *
  122. *        CHECKBOX_KIND:
  123. *
  124. *            current GTCB_Checked state
  125. *
  126. *        LISTVIEW_KIND:
  127. *
  128. *            current GTLV_Selected state
  129. *
  130. *        MX_KIND:
  131. *
  132. *            current GTMX_Active state
  133. *
  134. *        CYCLE_KIND:
  135. *
  136. *            current GTCY_Active state
  137. *
  138. *        POPUP_KIND:
  139. *
  140. *            current LAPU_Active state
  141. *
  142. *        TAB_KIND:
  143. *
  144. *            current LATB_Active state
  145. *
  146. *        PALETTE_KIND:
  147. *
  148. *            current GTPA_Color state
  149. *
  150. *        SLIDER_KIND:
  151. *
  152. *            current GTSL_Level state
  153. *
  154. *        GAUGE_KIND:
  155. *
  156. *            current LAGA_Percent state
  157. *
  158. *        STRING_KIND:
  159. *
  160. *            pointer to current string
  161. *
  162. *        PASSWORD_KIND:
  163. *
  164. *            pointer to current string
  165. *
  166. *        INTEGER_KIND:
  167. *
  168. *            number currently entered
  169. *
  170. *        BOOPSI_KIND:
  171. *
  172. *            whatever the object thinks is its
  173. *            current value
  174. *
  175. *        TEXTEDIT_KIND:
  176. *
  177. *            pointer to current string
  178. *
  179. ******************************************************************************
  180. *
  181. */
  182.  
  183. LONG LIBENT
  184. LT_GetAttributesA(REG(a0) LayoutHandle *Handle,REG(d0) LONG ID,REG(a1) struct TagItem *TagList)
  185. {
  186.     if(Handle)
  187.     {
  188.         struct TagItem    *ThisTag;
  189.         ObjectNode        *Node = NULL;
  190.  
  191.         if(ThisTag = FindTagItem(LAPR_Gadget,TagList))
  192.             Node = ((struct Gadget *)ThisTag->ti_Data)->UserData;
  193.  
  194.         if(!Node)
  195.         {
  196.             if(ThisTag = FindTagItem(LAPR_Object,TagList))
  197.                 Node = (ObjectNode *)ThisTag->ti_Data;
  198.         }
  199.  
  200.         if(!Node)
  201.             Node = LTP_FindNode(Handle,ID);
  202.  
  203.         if(Node)
  204.         {
  205.             struct Gadget *Gadget = Node->Host;
  206.  
  207.             if(TagList)
  208.             {
  209.                 struct TagItem    *TagItem,
  210.                                 *TempPtr = TagList;
  211.                 LONG            *Value;
  212.  
  213.                 while(TagItem = NextTagItem(&TempPtr))
  214.                 {
  215.                     Value = (LONG *)TagItem->ti_Data;
  216.  
  217.                     switch(TagItem->ti_Tag)
  218.                     {
  219.                         case LA_Left:
  220.  
  221.                             if(Node->Type == FRAME_KIND && Node->Special.Frame.DrawBox)
  222.                                 *Value = Node->Left + 4;
  223.                             else
  224.                                 *Value = Node->Left;
  225.  
  226.                             break;
  227.  
  228.                         case LA_Top:
  229.  
  230.                             if(Node->Type == FRAME_KIND && Node->Special.Frame.DrawBox)
  231.                                 *Value = Node->Top + 2;
  232.                             else
  233.                                 *Value = Node->Top;
  234.  
  235.                             break;
  236.  
  237.                         case LA_Width:
  238.  
  239.                             if(Node->Type == FRAME_KIND && Node->Special.Frame.DrawBox)
  240.                                 *Value = Node->Width - 8;
  241.                             else
  242.                                 *Value = Node->Width;
  243.  
  244.                             break;
  245.  
  246.                         case LA_Height:
  247.  
  248.                             if(Node->Type == FRAME_KIND && Node->Special.Frame.DrawBox)
  249.                                 *Value = Node->Height - 4;
  250.                             else
  251.                                 *Value = Node->Height;
  252.  
  253.                             break;
  254.  
  255.                         case LAST_CursorPosition:
  256.  
  257.                             *Value = 0;
  258.  
  259.                             if(Node->Type == STRING_KIND || Node->Type == FRACTION_KIND)
  260.                             {
  261.                                 if(Gadget != NULL)
  262.                                 {
  263.                                     struct StringInfo *StringInfo = Gadget->SpecialInfo;
  264.  
  265.                                     *Value = StringInfo->BufferPos;
  266.                                 }
  267.                             }
  268.  
  269.                             #ifdef DO_TEXTEDIT_KIND
  270.                             {
  271.                                 if(Node->Type == TEXTEDIT_KIND && Gadget != NULL)
  272.                                 {
  273.                                     GetAttr(STRINGA_BufferPos,Gadget,(ULONG *)&Value);
  274.                                 }
  275.                             }
  276.                             #endif /* DO_TEXTEDIT_KIND */
  277.  
  278.                             break;
  279.  
  280.                         #ifdef DO_BOOPSI_KIND
  281.                         {
  282.                             case LABO_Object:
  283.  
  284.                                 if(Node->Type == BOOPSI_KIND)
  285.                                     *Value = (LONG)Node->Host;
  286.                                 else
  287.                                     *Value = NULL;
  288.  
  289.                                 break;
  290.                         }
  291.                         #endif    /* DO_BOOPSI_KIND */
  292.  
  293.                         case LA_Chars:
  294.  
  295.                             *Value = Node->Chars;
  296.                             break;
  297.  
  298.                         case LA_Lines:
  299.  
  300.                             *Value = Node->Lines;
  301.                             break;
  302.  
  303.                         case LA_LabelLeft:
  304.  
  305.                             switch(Node->LabelPlace)
  306.                             {
  307.                                 case PLACE_LEFT:
  308.  
  309.                                     *Value    = Node->Left - (INTERWIDTH + Node->LabelWidth);
  310.                                     break;
  311.  
  312.                                 case PLACE_RIGHT:
  313.  
  314.                                     *Value    = Node->Left + Node->Width + INTERWIDTH;
  315.                                     break;
  316.  
  317.                                 case PLACE_ABOVE:
  318.  
  319.                                     *Value    = Node->Left + (Node->Width - Node->LabelWidth) / 2;
  320.                                     break;
  321.  
  322.                                 case PLACE_BELOW:
  323.  
  324.                                     *Value    = Node->Left + (Node->Width - Node->LabelWidth) / 2;
  325.                                     break;
  326.  
  327.                                 case PLACE_IN:
  328.  
  329.                                     *Value    = Node->Left + (Node->Width - Node->LabelWidth) / 2;
  330.                                     break;
  331.                             }
  332.  
  333.                             break;
  334.  
  335.                         case LA_LabelTop:
  336.  
  337.                             switch(Node->LabelPlace)
  338.                             {
  339.                                 case PLACE_LEFT:
  340.  
  341.                                     *Value    = Node->Top + (Node->Height - Handle->GlyphHeight) / 2;
  342.                                     break;
  343.  
  344.                                 case PLACE_RIGHT:
  345.  
  346.                                     *Value    = Node->Top + (Node->Height - Handle->GlyphHeight) / 2;
  347.                                     break;
  348.  
  349.                                 case PLACE_ABOVE:
  350.  
  351.                                     *Value    = Node->Top - (Handle->GlyphHeight + INTERHEIGHT);
  352.                                     break;
  353.  
  354.                                 case PLACE_BELOW:
  355.  
  356.                                     *Value    = Node->Top + Node->Height + INTERHEIGHT;
  357.                                     break;
  358.  
  359.                                 case PLACE_IN:
  360.  
  361.                                     *Value    = Node->Top + (Node->Height - Handle->GlyphHeight) / 2;
  362.                                     break;
  363.                             }
  364.  
  365.                             break;
  366.                     }
  367.                 }
  368.             }
  369.  
  370.             switch(Node->Type)
  371.             {
  372.                 case POPUP_KIND:
  373.                 case TAB_KIND:
  374.                 case GAUGE_KIND:
  375.                 case TAPEDECK_KIND:
  376.                 case LEVEL_KIND:
  377.  
  378.                 case CHECKBOX_KIND:
  379.                 case LISTVIEW_KIND:
  380.                 case MX_KIND:
  381.                 case CYCLE_KIND:
  382.                 case PALETTE_KIND:
  383.                 case SLIDER_KIND:
  384.                 case SCROLLER_KIND:
  385.  
  386.                     return(Node->Current);
  387.  
  388.                 #ifdef DO_BOOPSI_KIND
  389.                 {
  390.                     case BOOPSI_KIND:
  391.                     {
  392.                         ULONG Storage;
  393.  
  394.                         if(Gadget && GetAttr(Node->Special.BOOPSI.TagCurrent,Gadget,&Storage))
  395.                             return((LONG)Storage);
  396.                         else
  397.                             return(NULL);
  398.                     }
  399.                 }
  400.                 #endif    /* DO_BOOPSI_KIND */
  401.  
  402.                 #ifdef DO_TEXTEDIT_KIND
  403.                 {
  404.                     case TEXTEDIT_KIND:
  405.                     {
  406.                         ULONG Storage;
  407.  
  408.                         if(Gadget != NULL && GetAttr(STRINGA_Buffer,Gadget,&Storage))
  409.                             return((LONG)Storage);
  410.                         else
  411.                             return((LONG)Node->Special.TextEdit.String);
  412.                     }
  413.                 }
  414.                 #endif /* DO_TEXTEDIT_KIND */
  415.  
  416.                 case VERTICAL_KIND:
  417.                 case HORIZONTAL_KIND:
  418.  
  419.                     return((LONG)Node->Special.Group.ActivePage);
  420.  
  421.                 case STRING_KIND:
  422.                 case FRACTION_KIND:
  423.  
  424.                     if(Gadget)
  425.                     {
  426.                         if(Node->Type == FRACTION_KIND)
  427.                         {
  428.                             LTP_CopyFraction(Node->Special.String.RealString,((struct StringInfo *)Gadget->SpecialInfo)->Buffer);
  429.  
  430.                             return((LONG)Node->Special.String.RealString);
  431.                         }
  432.                         else
  433.                         {
  434.                             struct StringInfo *StringInfo;
  435.  
  436.                             StringInfo = (struct StringInfo *)Gadget->SpecialInfo;
  437.  
  438.                             return((LONG)StringInfo->Buffer);
  439.                         }
  440.                     }
  441.                     else
  442.                     {
  443.                         STRPTR String = Node->Special.String.String;
  444.  
  445.                         if(!String)
  446.                             String = "";
  447.  
  448.                         if(Node->Type == FRACTION_KIND)
  449.                         {
  450.                             LTP_CopyFraction(Node->Special.String.RealString,String);
  451.  
  452.                             String = Node->Special.String.RealString;
  453.                         }
  454.  
  455.                         return((LONG)String);
  456.                     }
  457.  
  458.                     break;
  459.  
  460.                 #ifdef DO_PASSWORD_KIND
  461.                 {
  462.                     case PASSWORD_KIND:
  463.  
  464.                         return((LONG)Node->Special.String.RealString);
  465.                 }
  466.                 #endif
  467.  
  468.                 case INTEGER_KIND:
  469.  
  470.                     if(Gadget != NULL)
  471.                     {
  472.                         struct StringInfo *    StringInfo;
  473.                         LONG                Contents;
  474.  
  475.                         StringInfo = (struct StringInfo *)Gadget->SpecialInfo;
  476.  
  477.                         Contents = StringInfo->LongInt;
  478.  
  479.                         if(Contents < Node->Min)
  480.                             Contents = Node->Min;
  481.                         else
  482.                         {
  483.                             if(Contents > Node->Max)
  484.                                 Contents = Node->Max;
  485.                         }
  486.  
  487.                         LT_SetAttributes(Handle,0,
  488.                             LAPR_Object,    Node,
  489.                             GTIN_Number,    Contents,
  490.                         TAG_DONE);
  491.  
  492.                         Node->Special.Integer.Number = Contents;
  493.                     }
  494.  
  495.                     return(Node->Special.Integer.Number);
  496.  
  497.                 case GROUP_KIND:
  498.  
  499.                     return((LONG)Node->Special.Group.ActivePage);
  500.             }
  501.         }
  502.         else
  503.         {
  504.             return((LONG)Handle->UserData);
  505.         }
  506.     }
  507.  
  508.     return(NULL);
  509. }
  510.